<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        button {
            width: 200px;
            height: 100px;
        }
    </style>
</head>

<body>
    <button id="but" onclick="hide()" >
        <h2 >封校三天，快乐无边</h2>
    </button>
    <script>
        var i = 1;
        var text = document.querySelector("#but h2").innerHTML;
        function hide() {
            //按钮按一次计数一次
            i++
            //获取div下的h2
            var a = document.querySelector("#but h2");
            //偶数把内容设为空
            if (i % 2 == 0) {
                a.style.display="none"
                //document.querySelector("#but h2").innerHTML = "";
            } else {
                a.style.display="block"
                //document.querySelector("#but h2").innerHTML = text;
            }
        }
    </script>


</body>

</html>